#import "UIHelper.h"
#import "MBProgressHUD.h"
@implementation UIHelper
+ (void)showLoadingInView:(UIView *)view hasText:(BOOL)hasText  {
    UIWindow *window = [[[UIApplication sharedApplication] windows] lastObject];
    UIView *container = (view != nil ? view : window);
    [self dismissLoadingInView:container];
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:container animated:YES];
    if (hasText) {
        hud.labelText = @"加载中...";
    }
}
+ (void)showLoadingInView:(UIView *)view {
    [self showLoadingInView:view hasText:NO];
}
+ (void)dismissLoadingInView:(UIView *)view {
    UIWindow *window = [[[UIApplication sharedApplication] windows] lastObject];
    UIView *container = (view != nil ? view : window);
    [MBProgressHUD hideHUDForView:container animated:YES];
}
+ (void)showTipsWithText:(NSString *)text inView:(UIView *)view {
    UIWindow *window = [[[UIApplication sharedApplication] windows] lastObject];
    UIView *container = (view != nil ? view : window);
    [self dismissLoadingInView:container];
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:container animated:YES];
    hud.mode = MBProgressHUDModeCustomView;
    hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"info"]];
    hud.detailsLabelFont = [UIFont boldSystemFontOfSize:16];
    hud.detailsLabelText = text;
    [hud hide:YES afterDelay:1.5];
}
+ (void)showErrorWithText:(NSString *)text inView:(UIView *)view {
    UIWindow *window = [[[UIApplication sharedApplication] windows] lastObject];
    UIView *container = (view != nil ? view : window);
    [self dismissLoadingInView:container];
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:container animated:YES];
    hud.mode = MBProgressHUDModeCustomView;
    hud.customView = [[UIImageView alloc] initWithImage:  [UIImage imageNamed:@"error"]];
    hud.detailsLabelFont = [UIFont boldSystemFontOfSize:16];
    hud.detailsLabelText = text;
    [hud hide:YES afterDelay:1.5];
}
+ (void)showMessage:(NSString *)message toView:(UIView *)view {
    if (view == nil) view = [[UIApplication sharedApplication].windows lastObject];
    [self dismissLoadingInView:view];
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud.labelText = message;
    hud.removeFromSuperViewOnHide = YES;
    hud.dimBackground = NO;
}
+ (void)showdetailMessage:(NSString *)message toView:(UIView *)view {
    if (view == nil) view = [[UIApplication sharedApplication].windows lastObject];
    [self dismissLoadingInView:view];
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud.removeFromSuperViewOnHide = YES;
    hud.detailsLabelText = message;
    hud.dimBackground = NO;
}
@end
